import resource from '../lib/resource';
var log = {};

/**
 * 登录
 */
log.getuser = function () {
    //获取用户信息
    wx.getUserInfo({
      success: (res) => {
        //全局变量
        var app = getApp();
          app.globalData.userInfo = res.userInfo;
          //console.log(app.globalData.userInfo);
      },
      fail: (res) => {
        //console.log(res);
      }
    });
}

log.verificationToken = function (returndata) {
  let token = wx.getStorageSync('token');
  //console.log(token);
  if(token == ''){
    wx.showToast({
      title: '请重新登录',
      icon: 'none',
      duration: 2000, //持续的时间
    });
    return false;
  }
  
  if(returndata.errCode == 201){
    wx.showToast({
      title: returndata.message,
      icon: 'none',
      duration: 2000, //持续的时间
    });
    return false;
  }

  if (returndata.errCode == 203) {
    //删除token
    wx.removeStorage({
      key: 'token',
    });
    wx.showToast({
      title: '请重新登录',
      icon: 'none',
      duration: 2000, //持续的时间
    });
    setTimeout(() => {
    }, 2000);
   
    return false;
  }
  return  true;
}
module.exports = {
  log: log
}